import json  #获得数据，打开疫情.txt
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts


f= open("C:\\Users\\29479\\Desktop\\自动化测试\\资料\\资料\\可视化案例数据\\地图数据\\疫情.txt",'r',encoding='utf-8')

data_f=f.read()
f.close()
#得到数据了要转化
data_dict=json.loads(data_f)

#获得河南数据
data_henan=data_dict['areaTree'][0]['children'][3]["children"]

#准备数据为元组，放入list
data=[]
for list1 in data_henan:#循环这个data_henan,但是我不是全要，我只要市，和对应的人数
    city_name=list1['name']+'市'
    city_total = list1['total']['confirm']
    data.append((city_name,city_total))


#手动添加济源市
data.append(('济源市',5))

map = Map()
map.add('河南省',data,'河南')






map.set_global_opts(
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 9, "label": '0-9', "color": "#d29a98"},
            {"min": 10, "max": 99, "label": '10-99', "color": "#c87c79"},
            {"min": 100, "max": 999, "label": '100-999', "color": "#c45854"},
            {"min": 1000, "max": 9999, "label": '1000-9999', "color": "#bc3934"},
            {"min": 10000, "max": 99999, "label": '10000-99999', "color": "#882420"}
        ]

    )
)
map.render("河南省地图.html")








